//
//  PhotoScrollView.m
//  Movie
//
//  Created by tengyang on 15/7/23.
//  Copyright (c) 2015年 tengyang. All rights reserved.
//

#import "PhotoScrollView.h"
#import "UIImageView+WebCache.h"

@implementation PhotoScrollView

- (id)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self) {
        _imageView=[[UIImageView alloc]initWithFrame:self.bounds];
        [self addSubview:_imageView];
        _imageView.contentMode=UIViewContentModeScaleAspectFit;
        
        
        //以下实现了图片的放大，双击放大，单击隐藏导航栏
        self.delegate=self;
        self.minimumZoomScale=0.5;
        self.maximumZoomScale=3;
        
        //设置手势的定义
        UITapGestureRecognizer *doubleTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doubleTap)];
        //默认为单击
        //敲击的次数                                           
        doubleTap.numberOfTapsRequired=2;
        //触摸点的个数
        doubleTap.numberOfTouchesRequired=1;
        [self addGestureRecognizer:doubleTap];
        
        
        UITapGestureRecognizer *singleTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singleTap)];
        [self addGestureRecognizer:singleTap];
        [singleTap requireGestureRecognizerToFail:doubleTap];
        
    }
    return self;
}

- (void)singleTap
{
    //通知，在PhotoViewController上接受通知，让它去实现隐藏导航栏
    [[NSNotificationCenter defaultCenter]postNotificationName:@"hiddenNav" object:nil];
    
    
}
- (void)doubleTap
{
    if (self.zoomScale==1) {
        [self setZoomScale:3 animated:YES];
    }
    else
    {
        [self setZoomScale:1 animated:YES];
    }
    
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return _imageView;
}


- (void)setUrlStr:(NSString *)urlStr
{
    _urlStr=urlStr;
    [self setNeedsLayout];
}

- (void)layoutSubviews
{
    [_imageView sd_setImageWithURL:[NSURL URLWithString:_urlStr]];
    
}

@end
